﻿using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;

namespace Kz.Telegram.Bot.Console.HandleUpdate
{
    public class MyChatMemberHandler : IHandler
    {
        public async Task Handle(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
        {
            var member = update.MyChatMember!;

            //群组信息
            var group_id = member.Chat.Id;
            var group_name = member.Chat.Title;
            var group_username = member.Chat.Username;

            //来源用户
            var from_id = member.From.Id;
            var from_username = member.From.Username;


            //将机器人拉进群
            if (member.NewChatMember.User.IsBot && member.NewChatMember.Status == ChatMemberStatus.Administrator)
            {
                //发送进群消息
                var sayhi = await System.IO.File.ReadAllTextAsync("Texts/joined_group_sayhi.txt");
                await botClient.SendTextMessageAsync(member.Chat.Id, sayhi, cancellationToken: cancellationToken,
                    replyMarkup: new InlineKeyboardMarkup(InlineKeyboardButton.WithUrl(text: "👉 ⚙️ 进入管理菜单 👈", url: $"https://t.me/{Bot.UserName}")));

                //入库保存 , 在用户{from_username}与机器人私聊时，可以查询出来绑定对应的群组列表进行业务参数的设置管理
                //...



            }
            //将用户好友拉进群
            else
            {

            }
        }
    }
}